package cn.com.huzo.repository.inventory.impl;

import cn.com.huzo.model.entities.inventory.StockInLinesPoHeaderEntity;
import cn.com.huzo.repository.inventory.StockInLinesPoHeaderRepository;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * 入库单-引入的采购订单主表数据访问对象。
 *
 * @author 吴旭
 */
@Repository("StockInLinesPoHeaderRepository")
public class StockInLinesPoHeaderRepositoryImpl extends GenericRepositoryImpl<StockInLinesPoHeaderEntity, String>
        implements StockInLinesPoHeaderRepository {

    private final String namespace = "cn.com.huzo.repository.inventory.StockInLinesPoHeaderRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public StockInLinesPoHeaderRepositoryImpl() {
        super(StockInLinesPoHeaderEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<StockInLinesPoHeaderEntity> fetchByHeaderKey(Long headerId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);

        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByHeaderId"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insertLines(Long headerId, List<Long> poHeaderIdList, Long userId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("PoHeaderIdList", poHeaderIdList);
        criterion.put("CreatedBy", userId);
        criterion.put("UpdatedBy", userId);

        // 影响的行数
        int rowsAffected = getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insert"), criterion);

        // 返回出入后的记录ID
        return rowsAffected;
    }
}
